package com.jdz.gxq.info.admin.logon.service;

import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import jp.terasoluna.fw.web.RequestUtil;
import jp.terasoluna.fw.web.thin.AuthenticationController;

import org.apache.log4j.Logger;

import com.jdz.gxq.info.common.bo.SessionUserInfo;
import com.jdz.gxq.info.common.constant.Constant;

public class LogonAuthenticationController implements AuthenticationController {

    private Logger log = Logger.getLogger(AuthenticationController.class);
    
    private List<String> listNoCheckRequiredPath = null;
    

    public List<String> getListNoCheckRequiredPath() {
        return listNoCheckRequiredPath;
    }

    public void setListNoCheckRequiredPath(
    		List<String> listNoCheckRequiredPath) {
        this.listNoCheckRequiredPath = listNoCheckRequiredPath;
    }

    public boolean isAuthenticated(String pathInfo, ServletRequest req) {
        
        if (log.isDebugEnabled()) {
            log.debug("isAuthenticated() strated.");
        }
        
        HttpSession session = ((HttpServletRequest) req).getSession();
        
        SessionUserInfo user = (SessionUserInfo) session.getAttribute(Constant.SEESION_USER_KEY);
        
        if (user != null) {
            return true;
        }
        
        if (log.isDebugEnabled()) {
            log.debug("isAuthenticated() ended.");
        }
        return false;
    }

    public boolean isCheckRequired(ServletRequest req) {
        
        if (log.isDebugEnabled()) {
            log.debug("isCheckRequired() strated.");
        }
        
        System.out.println(RequestUtil.getPathInfo(req));
        
        for (String path : listNoCheckRequiredPath) {
            if ((RequestUtil.getPathInfo(req)).equals(path)) {
                return false;
            }
        }
        
        if (log.isDebugEnabled()) {
            log.debug("isCheckRequired() ended.");
        }
        return true;
    }
}